package com.cloud.adrian.novel.search.controller;

import com.cloud.adrian.novel.book.dto.req.BookSearchReqDto;
import com.cloud.adrian.novel.book.dto.resp.BookInfoRespDto;
import com.cloud.adrian.novel.common.constant.ApiRouterConstants;
import com.cloud.adrian.novel.common.resp.PageRespDto;
import com.cloud.adrian.novel.common.resp.RestResp;
import com.cloud.adrian.novel.search.service.SearchService;
import com.cloud.adrian.novel.search.task.BookToEsTask;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 搜索模块前台接口
 * @Author: xiangguiliang
 * @version: 1.0
 * @since: 2024/05/26
 */
@Tag(name = "SearchController", description = "前台门户-搜索接口")
@RestController
@RequestMapping(ApiRouterConstants.API_FRONT_SEARCH_URL_PREFIX)
@RequiredArgsConstructor
public class SearchController {

    private final SearchService searchService;
    private final BookToEsTask bookToEsTask;

    @Operation(summary = "搜索小说接口")
    @GetMapping("books")
    public RestResp<PageRespDto<BookInfoRespDto>> searchBooks(
            @ParameterObject BookSearchReqDto condition) {
        return searchService.searchBooks(condition);
    }

    @GetMapping("/task")
    public String task() {
        bookToEsTask.saveToEs();
        return "success";
    }

}
